import 'package:Second/routerdemo/TabsLogin.dart';
import 'package:Second/routerdemo/user/Login.dart';
import 'package:Second/routerdemo/user/Register.dart';
import 'package:Second/routerdemo/user/RegisterFirst.dart';
import 'package:flutter/material.dart';

import 'routerdemo/user/RegisterNext.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  final Map<String, Function> routes = {
    "/": (context) => TabsLogin(),
    "/login": (context) => LoginPage(),
    "/register": (context) => RegisterPage(),
    "/register/first": (context) => RegisterFirst(),
    "/register/next": (context) => RegisterNext()
  };
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: TabsLogin(),
      onGenerateRoute: (RouteSettings settings) {
        final String? name = settings.name;
        final Function? pageContentBuilder = this.routes[name];

        if (pageContentBuilder != null) {
          if (settings.arguments != null) {
            final Route route = MaterialPageRoute(
                builder: (context) =>
                    pageContentBuilder(context, arguments: settings.arguments));
            return route;
          } else {
            final Route route = MaterialPageRoute(
                builder: (context) => pageContentBuilder(context));
            return route;
          }
        }
      },
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}
